package cn.lisens.async.web;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AsyncController {

	@GetMapping("/async/callable")
    public Callable<String> asyncCallable() {
        return () -> {
            // 模拟长时间任务
            Thread.sleep(3000);
            return "异步请求完成 - " + Thread.currentThread().getName();
        };
    }
	    
	    @GetMapping("/async/callable-with-data")
	    public Callable<ResponseEntity<Map<String, Object>>> asyncCallableWithData() {
	        return () -> {
	            // 模拟业务处理
	            Thread.sleep(2000);
	            
	            Map<String, Object> result = new HashMap<>();
	            result.put("status", "success");
	            result.put("data", "处理完成");
	            result.put("timestamp", System.currentTimeMillis());
	            result.put("thread", Thread.currentThread().getName());
	            
	            return ResponseEntity.ok(result);
	        };
	    }
}
